﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WoChu.RfClient.Entity;

namespace WoChu.RfClient.Duty
{
    public partial class FrmBindBoxCode : Form
    {
        private bool IsOrder;
        public FrmBindBoxCode(bool IsOrder)
        {
            this.IsOrder = IsOrder;
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtBoxCode.Text))
            {
                MessageBox.Show("请扫描箱号！");
                return;
            }
            if (IsOrder)
            {
                if (FrmOffShelvesOrder.goodsBox == null)
                    FrmOffShelvesOrder.goodsBox = new GoodsBoxes();
                FrmOffShelvesOrder.goodsBox.GOODSBOXCODE = txtBoxCode.Text.Trim();
                FrmOffShelvesOrder.goodsBox.RATIONDATE = !string.IsNullOrEmpty(dtpBestTime.Text.Trim()) ? Convert.ToDateTime(dtpBestTime.Text) : DateTime.MinValue;
                FrmOffShelvesOrder.goodsBox.BATCHNO = !string.IsNullOrEmpty(txtBatchNo.Text.Trim()) ? Convert.ToInt32(txtBatchNo.Text) : 0;
            }
            else
            {
                if (FrmOffShelves.goodsBox == null)
                    FrmOffShelves.goodsBox = new GoodsBoxes();
                FrmOffShelves.goodsBox.GOODSBOXCODE = txtBoxCode.Text.Trim();
                FrmOffShelves.goodsBox.RATIONDATE = !string.IsNullOrEmpty(dtpBestTime.Text.Trim()) ? Convert.ToDateTime(dtpBestTime.Text) : DateTime.MinValue;
                FrmOffShelves.goodsBox.BATCHNO = !string.IsNullOrEmpty(txtBatchNo.Text.Trim()) ? Convert.ToInt32(txtBatchNo.Text) : 0;
            }
            this.Close();
        }

        private void FrmBindBoxCode_Load(object sender, EventArgs e)
        {
            txtBoxCode.Focus();
            dtpBestTime.CustomFormat = "yyyy-MM-dd";
            dtpBestTime.Text = DateTime.Now.ToString();
        }

        private void txtBoxCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
                return;
            else
                txtBatchNo.Focus();
        }

        private void txtBatchNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
                return;
            else
                dtpBestTime.Focus();
        }

      
    }
}